import path = require('path')
import { FileUtil } from 'tools-mock'

//转存到的目录
const iconUrl = path.join(__dirname, './zipdir')

/**
 * 将iconfont插件导出为组件的ts文件生成data.ts导入数据给getOne.ts使用
 */
const init = async () => {
    let arr = []
    await FileUtil.readDirectory(iconUrl, (filename) => {
        if (filename.endsWith('.ts')) {
            let _url = filename.split(iconUrl + '/')[1].split('/')[0]
            arr.push(_url)
        }
    })

    let res = ''
    arr.forEach((item) => {
        res += `
        import { ${item}Json, ${item}Name } from './zipdir/${item}/${item}';
        `
    })
    res += `
    export default {
    `
    arr.forEach((item) => {
        res += `
        [${item}Name]:${item}Json,
        `
    })
    res += `
        }
    `
    FileUtil.writeFile(path.join(__dirname, './data.ts'), res)
}

init()
